package cn.cxy.demo

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        queryData()
    }

    private fun queryData() {
        val networkService = getNetworkService()
        val call = networkService.query()
        call.enqueue(object : Callback<Task?> {
            override fun onResponse(call: Call<Task?>?, response: Response<Task?>) {
                val bean: Task? = response.body()
                contentTv.text = bean?.name
            }

            override fun onFailure(call: Call<Task?>?, t: Throwable) {
                Log.e("MainActivity", "网络请求失败:" + t.message)
            }
        })
    }
}
